package ext.tianma.version;

import wt.fc.Persistable;
import wt.fc.ReferenceFactory;
import wt.fc.WTReference;
import wt.util.WTException;

/**Description: 公用验证类
 * @author    :  YangWen
 * @create at :  2013-7-19  上午11:47:43
 */
public class ComToolUtil {
	
	private ComToolUtil(){
		
	}
	
	/**检查obj是否为空或者空字符串
	 * @param obj
	 * @return
	 */
	public static boolean isEmpty(Object obj){
		if(obj == null || obj.toString().trim().length() == 0)
			return true;
		return false;
	}
	
	/**检验s是否为空或者空字符串
	 * @param s 指定的字符串
	 */
	public static boolean isEmpty(String s){
		if(s==null || s.trim().length() == 0)
			return true;
		else
			return false;
	}
	
	 /**通过oid来获得对象
     * @param oid  对象的oid
     * @return oid所对应的对象
     */
    public static Persistable getPersistableFromOid(String oid) {
    	if(ComToolUtil.isEmpty(oid))
    		return null;
    	
		try {
		    ReferenceFactory refFactory = new ReferenceFactory();
		    WTReference reference = refFactory.getReference(oid);
		    if (reference == null) 
		    	return null;	    
		    return reference.getObject();
		} catch (WTException e) {
		    e.getMessage();
		}
		
		return null;
    }

}
